package com.intermancer.predictor.lifecycle;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.chain.impl.ChainBase;

public class LifecycleDirectorImpl implements LifecycleDirector {
	
	private List<LifecycleListener> listeners;
	private ChainBase commandChain;
	private LifecycleContext context;
	
	public LifecycleDirectorImpl() {
		listeners = new ArrayList<LifecycleListener>();
	}
	
	public LifecycleDirectorImpl(ChainBase commandChain) {
		this();
		setCommandChain(commandChain);
	}
	
	@Override
	public void executeLifecycle() throws Exception {
		context = new LifecycleContext();
		if(commandChain.execute(context)) {
			// Something stopped the chain.  Handle it.
		}
	}

	public List<LifecycleListener> getListeners() {
		return listeners;
	}

	public ChainBase getCommandChain() {
		return commandChain;
	}

	public void setCommandChain(ChainBase commandChain) {
		this.commandChain = commandChain;
	}

	public LifecycleContext getContext() {
		return context;
	}

}
